﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HotManage.aspx.cs" Inherits="HotManage" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var updateRecord = function (form) {
            if (form.record == null) {
                return;
            }

            if (!form.getForm().isValid()) {
                Ext.net.Notification.show({
                    iconCls: "icon-exclamation",
                    html: "Form is invalid",
                    title: "Error"
                });
                return false;
            }

            form.getForm().updateRecord(form.record);
        };

        var addRecord = function (form, grid) {
            if (!form.getForm().isValid()) {
                Ext.net.Notification.show({
                    iconCls: "icon-exclamation",
                    html: "Form is invalid",
                    title: "Error"
                });

                return false;
            }

            grid.insertRecord(0, form.getForm().getFieldValues(false, "dataIndex"));
            form.getForm().reset();
        };
    </script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <form id="form1" runat="server">
    <div>
        <ext:Store ID="SStore" runat="server">
            <Reader>
                <ext:JsonReader IDProperty="id">
                    <Fields>
                        <ext:RecordField Name="id" />
                        <ext:RecordField Name="Store" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        <ext:Store ID="Store1" runat="server" AutoSave="true" ShowWarningOnFailure="false"
            OnBeforeStoreChanged="HandleChanges" SkipIdForNewRecords="false" RefreshAfterSaving="None">
            <Reader>
                <ext:JsonReader IDProperty="id">
                    <Fields>
                        <ext:RecordField Name="id" />
                        <ext:RecordField Name="url" AllowBlank="false" />
                        <ext:RecordField Name="img" AllowBlank="false" />
                        <ext:RecordField Name="storeid" AllowBlank="false" />
                        <ext:RecordField Name="text" AllowBlank="false" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <%-- <Listeners>
                <Exception Handler="
                    Ext.net.Notification.show({
                        iconCls    : 'icon-exclamation', 
                        html       : e.message, 
                        title      : 'EXCEPTION', 
                        autoScroll : true, 
                        hideDelay  : 5000, 
                        width      : 300, 
                        height     : 200
                    });" />
                <BeforeSave Handler="var valid = true; this.each(function(r){if(r.dirty && !r.isValid()){valid=false;}}); return valid;" />
            </Listeners>--%>
        </ext:Store>
        <ext:Hidden ID="UseConfirmation" runat="server" Text="false" />
        <ext:ComboBox ID="ComboBox3" StoreID="SStore" Width="250" Editable="false" FieldLabel="店铺"
            DataIndex="storeid" ValueField="id" DisplayField="Store" TypeAhead="true" Mode="Local"
            ForceSelection="true" TriggerAction="All" SelectOnFocus="true" runat="server">
        </ext:ComboBox>
        <ext:Button ID="Button8" runat="server" Text="Submit" OnDirectClick="Button8_DirectClick">
        </ext:Button>
        <ext:FormPanel ID="UserForm" runat="server" Icon="User" Frame="true" LabelAlign="Right"
            Title="User -- All fields are required" Width="500">
            <Items>
                <ext:TextField ID="TextField1" runat="server" FieldLabel="链接" DataIndex="url" AllowBlank="false"
                    AnchorHorizontal="100%" />
                <ext:TextField ID="TextField2" runat="server" FieldLabel="图片" DataIndex="img" AllowBlank="false"
                    AnchorHorizontal="100%" />
                <ext:ComboBox ID="ComboBox1" StoreID="SStore" Width="250" Editable="false" FieldLabel="店铺"
                    DataIndex="storeid" ValueField="id" DisplayField="Store" TypeAhead="true" Mode="Local"
                    ForceSelection="true" TriggerAction="All" SelectOnFocus="true" runat="server">
                </ext:ComboBox>
                <ext:TextField ID="TextField7" runat="server" FieldLabel="文字" DataIndex="text" AllowBlank="false"
                    AnchorHorizontal="100%" />
            </Items>
            <Buttons>
                <ext:Button ID="Button1" runat="server" Text="Save" Icon="Disk">
                    <Listeners>
                        <Click Handler="updateRecord(#{UserForm});" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="Button2" runat="server" Text="Create" Icon="UserAdd">
                    <Listeners>
                        <Click Handler="addRecord(#{UserForm}, #{GridPanel1});" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="Button3" runat="server" Text="Reset">
                    <Listeners>
                        <Click Handler="#{UserForm}.getForm().reset();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:FormPanel>
        <ext:GridPanel ID="GridPanel1" runat="server" Icon="Table" Frame="true" Title="Users"
            Height="400" Width="500" StoreID="Store1" StyleSpec="margin-top: 10px">
            <ColumnModel>
                <Columns>
                    <ext:Column Header="ID" Width="40" DataIndex="id" />
                    <ext:Column Header="链接" Width="100" DataIndex="url">
                        <Editor>
                            <ext:TextField ID="TextField4" runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:Column Header="图片" Width="50" DataIndex="img">
                        <Editor>
                            <ext:TextField ID="TextField5" runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:Column Header="店铺ID" Width="50" DataIndex="storeid">
                        <Editor>
                            <ext:ComboBox ID="ComboBox2" StoreID="SStore" Editable="false" DataIndex="storeid"
                                ValueField="id" DisplayField="Store" TypeAhead="true" Mode="Local" ForceSelection="true"
                                TriggerAction="All" SelectOnFocus="true" runat="server">
                            </ext:ComboBox>
                        </Editor>
                    </ext:Column>
                    <ext:Column Header="文字" Width="50" DataIndex="text">
                        <Editor>
                            <ext:TextField ID="TextField10" runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:CommandColumn Width="40">
                        <Commands>
                            <ext:GridCommand Text="Reject" ToolTip-Text="Reject row changes" CommandName="reject"
                                Icon="ArrowUndo" />
                        </Commands>
                        <PrepareToolbar Handler="toolbar.items.get(0).setVisible(record.dirty);" />
                    </ext:CommandColumn>
                </Columns>
            </ColumnModel>
            <Listeners>
                <Command Handler="record.reject();" />
            </Listeners>
            <View>
                <ext:GridView ID="GridView1" runat="server" ForceFit="true" />
            </View>
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="Button4" runat="server" Text="Add" Icon="Add">
                            <Listeners>
                                <Click Handler="#{GridPanel1}.insertRecord();" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="Button5" runat="server" Text="Delete" Icon="Exclamation">
                            <Listeners>
                                <Click Handler="if( confirm('r u sure del')){#{GridPanel1}.deleteSelected();#{UserForm}.getForm().reset();}" />
                            </Listeners>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="Button6" runat="server" Text="Auto Save" EnableToggle="true" Pressed="true"
                            ToolTip="When enabled, Store will execute Ajax requests as soon as a Record becomes dirty.">
                            <Listeners>
                                <Toggle Handler="#{Store1}.autoSave = pressed;#{Store1}.useIdConfirmation = !pressed;#{UseConfirmation}.setValue(!pressed);" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
                    <Listeners>
                        <RowSelect Handler="#{UserForm}.getForm().loadRecord(record);#{UserForm}.record = record;" />
                    </Listeners>
                </ext:RowSelectionModel>
            </SelectionModel>
            <Buttons>
                <ext:Button ID="Button7" runat="server" Text="Save" Icon="Disk">
                    <Listeners>
                        <Click Handler="#{GridPanel1}.save();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:GridPanel>
    </div>
    </form>
</body>
</html>
